﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace RTS_RPG
{
    public class Overworld_Creature
    {
        public List<Character> enemy_party;
        public int level;
        public Vector2 location;
        public Vector2 center_location;
        public int movement_distance;
        public int current_distance;
        public int direction;   // -1 means going left or up, 1 means going right or down.
        public bool vertical;   // if true this creature moves up and down on the world map, 
                                // otherwise it moves left and right.

        public Overworld_Creature(int lvl, Vector2 start_loc, int move_dist, bool up_down, 
            Player_TextureManager textures)
        {
            level = lvl;
            location = start_loc;
            center_location = start_loc;
            movement_distance = move_dist;
            current_distance = Program.Random.Next(movement_distance);
            vertical = up_down;

            int check = Program.Random.Next();
            if (check % 2 != 0) direction = -1;
            else direction = 1;

            Vector4 stats = new Vector4(3, 0, 16, 0);
            Vector2 hp = new Vector2(30, 30);
            Vector2 mp = new Vector2(20, 20);

            enemy_party = new List<Character>();
            for (int i = 0; i < 2 + Program.Random.Next(level / 4); ++i)
            {
                enemy_party.Add(new Character("Monster", hp, mp, new Vector2(Program.NaN, Program.NaN), 
                    1, 5, stats, 0, textures.unit_default_avatar,
                    textures.unit_default_image, null, null, null, null));
            }
        }

        public void update()
        {
            if (direction == -1)
            {
                --current_distance;
                if (vertical) location.Y = location.Y - 2;
                else location.X = location.X - 2;
            }
            else
            {
                ++current_distance;
                if (vertical) location.Y = location.Y + 2;
                else location.X = location.X + 2;
            }
            if (current_distance <= 0 || current_distance >= movement_distance)
                direction = -direction;
        }

        public void draw(SpriteBatch spBatch)
        {
            enemy_party[0].draw(spBatch, location);
        }
    }
}
